using System.Configuration;
using System.Windows;
using DotBeer.Data.Properties;
using DotBeer.UI.WPFClient.Options_Controls.CopyBuild;

namespace DotBeer.UI.WPFClient
{
	/// <summary>
	/// Interaction logic for UpdateOptionsControl.xaml
	/// </summary>
	public partial class UpdateOptionsControl : IOptionsControl
	{
		public UpdateOptionsControl()
		{
			this.InitializeComponent();

            UpdateSettings.Default.SettingsSaving += new SettingsSavingEventHandler(UpdateSettings_SettingsSaving);
            this.UpdateControls();
		}

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.UpdateControl.CheckUpdate();
        }

        #region ICopyBuildControl Members

        public bool Save()
        {
            UpdateSettings.Default.CheckAtStartup = (bool)this.checkBox.IsChecked;
            UpdateSettings.Default.Save();

            return true;
        }

        public void Cancel()
        {
        }

        private void UpdateControls()
        {
            this.checkBox.IsChecked = UpdateSettings.Default.CheckAtStartup;
        }

        void UpdateSettings_SettingsSaving(object sender, System.ComponentModel.CancelEventArgs e)
        {
            this.UpdateControls();
        }

        #endregion
    }
}